<?php
namespace app\services\ai\traits\qq;

trait VoiceMerge
{

    /**
     * 语音识别-echo版
     * @param array $options
     * @return mixed
     */
    public function aaiAsr(array $options)
    {
        return $this->request(self::POST, self::API_AAI_ASR, $this->parseOptions([
            'format' => $options['format'] ?? 2,
            'speech' => $options['speech'],
            'rate' => $options['rate'] ?? 16000,
        ]));
    }

    /**
     * 语音识别-AI LAB版
     * @param array $options
     * @return mixed
     */
    public function aaiAsrs(array $options)
    {
        return $this->request(self::POST, self::API_AAI_ASRS, $this->parseOptions([
            'speech_chunk' => $options['speech_chunk'] ?? '',
            'format' => $options['format'] ?? 2, //音频压缩格式 pcm wav...
            'rate' => $options['rate'] ?? 16000, //音频采样率编码
            'seq' => $options['seq'] ?? 0,       //语音分片所在语音流的偏移量
            'len' => $options['len'] ?? 1024,    //语音分片长度
            'end' => $options['end'] ?? 1,       //是否结束分片标识 0 中间分，结束分
            'speech_id' => str_random(64), //唯一ID
        ]));
    }

    /**
     * 语音识别-Wechat 版
     * @param $options
     * @return mixed
     */
    public function aaiWxars($options)
    {
        return $this->request(self::POST, self::API_AAI_WXARS, $this->parseOptions([
            'speech_chunk' => $options['speech_chunk'] ?? '',
            'format' => $options['format'] ?? 2, //音频压缩格式 pcm wav
            'rate' => $options['rate'] ?? 16000, //音频采样率编码
            'bits' => $options['bits'] ?? 16,    //音频采样位数
            'seq' => $options['seq'] ?? 0,       //语音分片所在语音流的偏移量
            'len' => $options['len'] ?? 1024,    //语音分片长度
            'end' => $options['end'] ?? 1,       //是否结束分片标识 0 中间分，结束分
            'speech_id' => str_random(64),       //唯一ID
            'cont_res' => $options['cont_res'] ?? 1, //是否获取中间识别结果
        ]));
    }

    /**
     * 文本合成语音 AI LAB
     * @param $options
     */
    public function aaiTts($options)
    {
        return $this->request(self::POST, self::API_AAI_TTS, $this->parseOptions([
            'speaker' => $options['speaker'] ?? array_rand([1 => 1, 5 => 5, 6 => 6, 7 => 7]),
            'format' => $options['format'] ?? self::AAI_TTS_FORMAT_MP3,
            'volume' => $options['volume'] ?? 0, // 音量 -10~10 default 0
            'speed' => $options['speed'] ?? 100, // 语速 50~200 default 100
            'text' => $options['text'] ?? '我不知道你说什么',
            'aht' => $options['aht'] ?? 0,  //音高 -24~24 default 0
            'apc' => $options['apc'] ?? 58,  //音色 0~100 default 58
        ]));
    }

    /**
     * 文本合成语音 优图版
     * @param $options
     * @return mixed
     */
    public function aaiTta($options)
    {
        return $this->request(self::POST, self::API_AAI_TTA, $this->parseOptions([
            'text' => $options['text'] ?? '我不知道你说什么',
            'model_type' => $options['model_type'] ?? array_rand([0 => 0, 1 => 1, 2 => 2, 6 => 6]), //0 1 2 6 default 0
            'speed' => $options['speed'] ?? 0, //-2~2  default 0
        ]));
    }
}